CC              ?= gcc
CFLAGS          ?= -O4 -ggdb -Wall -Wextra -Wno-unused-parameter
LDFLAGS         ?=

USE_ONIGURUMA   ?= 0
ONIG_ROOT       ?= oniguruma

GLIB_CFLAGS     ?= $(shell pkg-config --cflags glib-2.0)
GLIB_LDFLAGS    ?= $(shell pkg-config --libs glib-2.0)

ONIG_CFLAGS     ?= -I$(ONIG_ROOT)/include
ONIG_LDFLAGS    ?= -L$(ONIG_ROOT)/lib -lonig

ifeq ($(USE_ONIGURUMA),1)
CFLAGS_ALL      ?= $(CFLAGS) $(GLIB_CFLAGS) $(ONIG_CFLAGS) -DUSE_ONIGURUMA
LDFLAGS_ALL     ?= $(LDFLAGS) $(GLIB_LDFLAGS) $(ONIG_LDFLAGS)
else
CFLAGS_ALL      ?= $(CFLAGS) $(GLIB_CFLAGS)
LDFLAGS_ALL     ?= $(LDFLAGS) $(GLIB_LDFLAGS)
endif

statistic: statistic.o
	$(CC) $(LDFLAGS_ALL) -o $@ $<

.c.o:
	$(CC) $(CFLAGS_ALL) -c -o $@ $<

clean:
	rm *.o statistic
